package com.clei.netty.sync.encoder;

import com.clei.netty.sync.dto.MsgBody;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * MsgBody -> Byte Encoder
 *
 * @author Y
 * @date 2024-08-23
 */
public class MsgToByteEncoder extends MessageToByteEncoder<MsgBody> {

    @Override
    protected void encode(ChannelHandlerContext ctx, MsgBody msg, ByteBuf out) throws Exception {
        byte[] data = msg.toBytes();
        out.writeBytes(data);
    }
}
